package xhtml2pdf;

import java.util.HashMap;
import java.util.Vector;

import com.lowagie.text.Font;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfDestination;
import com.lowagie.text.pdf.PdfOutline;
import com.lowagie.text.pdf.PdfWriter;

public class OutLineHandler {
	private PdfWriter pdfWriter = null;
	private PdfContentByte pdfContentByte = null;
	private PdfOutline root = null;
	private HashMap<String, PdfOutline> hashMap = new HashMap<String, PdfOutline>();
	private String rootName = null;
	public OutLineHandler(PdfWriter pw, PdfContentByte pdfContentByte, String rootName){
		this.pdfWriter = pw;
		this.pdfContentByte = pdfContentByte;
		this.rootName = rootName;
		PdfAction dest = PdfAction.gotoLocalPage(1, new PdfDestination(
				PdfDestination.FITB), pdfWriter);
		PdfOutline root = new PdfOutline(pdfContentByte.getRootOutline(),dest,this.rootName,true); 
		if(pw != null){
			hashMap.put("-1",root);//rootlevel
		}
	}
	/**
	 * @param titleLevel : 0~6
	 * @param page : position of page
	 */
	public void generateOutline(int titleLevel, int page, String name){
		if( titleLevel>2 ) return;
		PdfAction dest = PdfAction.gotoLocalPage(page, new PdfDestination(
				PdfDestination.FITB), pdfWriter);
		PdfOutline po = new PdfOutline((PdfOutline)hashMap.get(String.valueOf(titleLevel-1)),dest,name,false);
		hashMap.put(String.valueOf(titleLevel), po);
	}
}
